package com.reconcile.phone.im;

import com.easemob.common.model.EasemobAppCredentials;
import com.easemob.im.server.EMProperties;
import com.easemob.im.server.EMService;
import com.easemob.push.EMPushProperties;
import com.easemob.push.EMPushService;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 注入IM service
 *
 * @author zlj
 * @since 2023/5/8
 */
@Data
//@Configuration
//@ConfigurationProperties(prefix = "imconfig")
public class IMProperties {

    private String appKey;

    private String clientId;

    public String clientSecret;

    @Bean
    public EMService service() {
        EMProperties properties = EMProperties.builder()
            .setAppkey(appKey)
            .setClientId(clientId)
            .setClientSecret(clientSecret)
            .build();
        return new EMService(properties);
    }

    @Bean
    public EMPushService emPushService() {
        EMPushProperties emPushProperties = EMPushProperties.builder()
            .setProtocol(EMPushProperties.Protocol.HTTPS)
            .setCredentials(EasemobAppCredentials.of(clientId, clientSecret))
            .setAppKey(appKey)
            .build();

        return new EMPushService(emPushProperties);
    }
}
